/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AltaGasto.java
 *
 * Created on 22/11/2011, 16:31:31
 */

package ar.lucas.controlgasto.modificaciones;

import ar.lucas.controlgasto.dao.ConceptoDTO;
import ar.lucas.controlgasto.dao.PersonaDAO;
import ar.lucas.controlgasto.utils.ReloadCombo;
import ar.lucas.controlgasto.utils.TableUtils;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import org.jdesktop.application.Action;

/**
 *
 * @author lucmussi
 */
public class ModificarGasto extends javax.swing.JDialog {
    boolean onePoint = false;
    boolean modif_persona = false;
    boolean modif_monto = false;
    boolean modif_tipo_gasto = false;
    boolean modif_fecha = false;
    boolean modif_descripcion = false;

    /** Creates new form AltaGasto */
    public ModificarGasto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    @Action public void cerrarVentanaModificarGasto() {
        dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmb_individuo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cmb_concepto = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jcal_fecha_gasto = new com.toedter.calendar.JDateChooser();
        jScrollPane1 = new javax.swing.JScrollPane();
        txta_descripcion = new javax.swing.JTextArea();
        btn_guardar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        txt_monto = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabla_gastos_modificaciones = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txt_busqueda = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlgasto.ControlGastoApp.class).getContext().getResourceMap(ModificarGasto.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION)); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        cmb_individuo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione..." }));
        cmb_individuo.setEnabled(false);
        cmb_individuo.setName("cmb_individuo"); // NOI18N
        cmb_individuo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmb_individuoActionPerformed(evt);
            }
        });

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        cmb_concepto.setEnabled(false);
        cmb_concepto.setName("cmb_concepto"); // NOI18N
        cmb_concepto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmb_conceptoActionPerformed(evt);
            }
        });

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jcal_fecha_gasto.setEnabled(false);
        jcal_fecha_gasto.setMinSelectableDate(new java.util.Date(915163263000L));
        jcal_fecha_gasto.setName("jcal_fecha_gasto"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txta_descripcion.setColumns(20);
        txta_descripcion.setRows(3);
        txta_descripcion.setEnabled(false);
        txta_descripcion.setName("txta_descripcion"); // NOI18N
        txta_descripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txta_descripcionKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(txta_descripcion);

        btn_guardar.setText(resourceMap.getString("btn_guardar.text")); // NOI18N
        btn_guardar.setEnabled(false);
        btn_guardar.setName("btn_guardar"); // NOI18N
        btn_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_guardarActionPerformed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(controlgasto.ControlGastoApp.class).getContext().getActionMap(ModificarGasto.class, this);
        jButton2.setAction(actionMap.get("cerrarVentanaModificarGasto")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setMaximumSize(new java.awt.Dimension(71, 23));
        jButton2.setMinimumSize(new java.awt.Dimension(71, 23));
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setPreferredSize(new java.awt.Dimension(71, 23));

        txt_monto.setEnabled(false);
        txt_monto.setName("txt_monto"); // NOI18N
        txt_monto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_montoKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btn_guardar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(85, 85, 85))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcal_fecha_gasto, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(53, 53, 53)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmb_individuo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_monto, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmb_concepto, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmb_individuo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmb_concepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_monto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jcal_fecha_gasto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(3, 3, 3)))
                        .addGap(74, 74, 74))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btn_guardar, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );

        ReloadCombo.llenarComboPersonas(cmb_individuo);
        ReloadCombo.llenarComboTipoGasto(cmb_concepto);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION)); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tabla_gastos_modificaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tabla_gastos_modificaciones.setName("tabla_gastos_modificaciones"); // NOI18N
        tabla_gastos_modificaciones.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabla_gastos_modificacionesMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabla_gastos_modificaciones);
        //TableUtils.fillTableHeaders(tabla_gastos_modificaciones);
        TableUtils.buscarAllGastosConId(tabla_gastos_modificaciones);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel3.border.title"), javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION)); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        txt_busqueda.setText(resourceMap.getString("txt_busqueda.text")); // NOI18N
        txt_busqueda.setName("txt_busqueda"); // NOI18N
        txt_busqueda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txt_busquedaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(211, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(200, 200, 200))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmb_individuoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmb_individuoActionPerformed
//        if(cmb_individuo.getSelectedIndex() == 0){
//            TableUtils.fillTableHeaders(tabla_gastos_alta);
//        }
//        else{
//            PersonaDAO persona = (PersonaDAO) cmb_individuo.getSelectedItem();
//            TableUtils.buscarAllGastos(tabla_gastos_alta, persona.getNombre());
//        }
        modif_persona = true;
        if(!btn_guardar.isEnabled())
            btn_guardar.setEnabled(true);
    }//GEN-LAST:event_cmb_individuoActionPerformed

    private void btn_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_guardarActionPerformed
        try{
            Double.parseDouble(txt_monto.getText());
        }
        catch(NumberFormatException ex){
            JOptionPane.showMessageDialog(null, "El formato del monto es incorrecto.","Error",JOptionPane.ERROR_MESSAGE);
        }
        if(cmb_individuo.getSelectedIndex() == 0)
            JOptionPane.showMessageDialog(null, "Seleccione un individuo","Error",JOptionPane.ERROR_MESSAGE);
        else if(txt_monto.getText().equals(""))
            JOptionPane.showMessageDialog(null, "Debe indicar el monto","Error",JOptionPane.ERROR_MESSAGE);
        else if(cmb_concepto.getSelectedIndex() == 0)
            JOptionPane.showMessageDialog(null, "Seleccione un concepto","Error",JOptionPane.ERROR_MESSAGE);
        else if(jcal_fecha_gasto.getDate() == null)
            JOptionPane.showMessageDialog(null, "Debe indicar la fecha","Error",JOptionPane.ERROR_MESSAGE);
        else if(txta_descripcion.getText().equals(""))
            JOptionPane.showMessageDialog(null, "Debe indicar la descripción","Error",JOptionPane.ERROR_MESSAGE);
        else {
            int row = tabla_gastos_modificaciones.getSelectedRow();
            PersonaDAO persona = (PersonaDAO) cmb_individuo.getSelectedItem();
            ConceptoDTO gastos = (ConceptoDTO) cmb_concepto.getSelectedItem();
            Integer id_gasto = (Integer) tabla_gastos_modificaciones.getModel().getValueAt(row, 0);
            Format sdf = new SimpleDateFormat("yyyy-MM-dd");
            String fecha_sel = sdf.format(jcal_fecha_gasto.getDate());
            if(modif_persona && modif_monto && modif_tipo_gasto && modif_descripcion){
                int id_tipo_gasto = gastos.getId_tipo_gasto();
                int id_persona = persona.getId_persona();
                String query = "UPDATE gastos SET denominacion = '"+txta_descripcion.getText()+"', monto = '"+txt_monto.getText()+"',"+
                               " fecha = '"+fecha_sel+"', id_tipo_gasto = "+id_tipo_gasto+", id_persona = "+id_persona+
                               " WHERE id_gasto = "+id_gasto;
                modif_persona = false;
                modif_monto = false;
                modif_tipo_gasto = false;
                modif_descripcion = false;
            }
            else if(modif_persona && modif_monto && modif_tipo_gasto){
                int id_tipo_gasto = gastos.getId_tipo_gasto();
                int id_persona = persona.getId_persona();
                String query = "UPDATE gastos SET monto = '"+txt_monto.getText()+"',"+
                               " fecha = '"+fecha_sel+"', id_tipo_gasto = "+id_tipo_gasto+", id_persona = "+id_persona+
                               " WHERE id_gasto = "+id_gasto;
                modif_persona = false;
                modif_monto = false;
                modif_tipo_gasto = false;
            }
            else if(modif_persona && modif_monto){
                int id_persona = persona.getId_persona();
                String query = "UPDATE gastos SET monto = '"+txt_monto.getText()+"',"+
                               " fecha = '"+fecha_sel+"', id_persona = "+id_persona+
                               " WHERE id_gasto = "+id_gasto;
                modif_persona = false;
                modif_monto = false;
            }
            else if(modif_persona){
                int id_persona = persona.getId_persona();
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', id_persona = "+id_persona+
                               " WHERE id_gasto = "+id_gasto;
                modif_persona = false;
            }
            else if(modif_monto){
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', monto = "+txt_monto.getText()+
                               " WHERE id_gasto = "+id_gasto;
                modif_monto = false;
            }
            else if(modif_monto && modif_tipo_gasto && modif_descripcion){
                int id_tipo_gasto = gastos.getId_tipo_gasto();
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', id_tipo_gasto = "+id_tipo_gasto+", monto = "+txt_monto.getText()+
                               ", denominacion = '"+txta_descripcion.getText()+"'"+
                               " WHERE id_gasto = "+id_gasto;
                modif_monto = false;
                modif_tipo_gasto = false;
                modif_descripcion = false;
            }
            else if(modif_monto && modif_descripcion){
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', monto = "+txt_monto.getText()+", denominacion = '"+txta_descripcion.getText()+"'"+
                               " WHERE id_gasto = "+id_gasto;
                modif_monto = false;
                modif_descripcion = false;
            }
            else if(modif_tipo_gasto){
                int id_tipo_gasto = gastos.getId_tipo_gasto();
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', id_tipo_gasto = "+id_tipo_gasto+
                               " WHERE id_gasto = "+id_gasto;
                modif_monto = false;
            }
            else if(modif_descripcion){
                String query = "UPDATE gastos SET fecha = '"+fecha_sel+"', denominacion = "+txta_descripcion.getText()+
                               " WHERE id_gasto = "+id_gasto;
                modif_monto = false;
            }
            if(btn_guardar.isEnabled())
                btn_guardar.setEnabled(false);
        }
    }//GEN-LAST:event_btn_guardarActionPerformed

    private void txt_montoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_montoKeyTyped
        char c = evt.getKeyChar();
        String st = String.valueOf(c);
        if(!Character.isDigit(c) && !st.equals(".")){
            evt.consume();
        }
        modif_monto = true;
        if(!btn_guardar.isEnabled())
            btn_guardar.setEnabled(true);

        /*
        if(onePoint == false){
            if (!Character.isDigit(c)) {
                if(st.equals(".")){
                    onePoint = true;
                } else {
                    evt.consume();
                }
            }
        } else if(!Character.isDigit(c)){
            evt.consume();
        }*/
    }//GEN-LAST:event_txt_montoKeyTyped

    private void txt_busquedaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_busquedaKeyReleased
        TableUtils.searchGastosByDetalle(txt_busqueda.getText(), tabla_gastos_modificaciones);
    }//GEN-LAST:event_txt_busquedaKeyReleased

    private void tabla_gastos_modificacionesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabla_gastos_modificacionesMouseClicked
        int row = tabla_gastos_modificaciones.getSelectedRow();
        txt_monto.setText(tabla_gastos_modificaciones.getModel().getValueAt(row, 3).toString());
        jcal_fecha_gasto.setDate((Date) tabla_gastos_modificaciones.getModel().getValueAt(row, 4));
        txta_descripcion.setText(tabla_gastos_modificaciones.getModel().getValueAt(row, 2).toString());
        cmb_individuo.setSelectedItem(ReloadCombo.seleccionaCombo(cmb_individuo, tabla_gastos_modificaciones.getModel().getValueAt(row, 1).toString()));
        cmb_concepto.setSelectedItem(ReloadCombo.seleccionaCombo(cmb_concepto, tabla_gastos_modificaciones.getModel().getValueAt(row, 5).toString()));
        txt_monto.setEnabled(true);
        jcal_fecha_gasto.setEnabled(true);
        cmb_concepto.setEnabled(true);
        cmb_individuo.setEnabled(true);
        txta_descripcion.setEnabled(true);
        if(btn_guardar.isEnabled())
            btn_guardar.setEnabled(false);
    }//GEN-LAST:event_tabla_gastos_modificacionesMouseClicked

    private void cmb_conceptoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmb_conceptoActionPerformed
        modif_tipo_gasto = true;
        if(!btn_guardar.isEnabled())
            btn_guardar.setEnabled(true);
    }//GEN-LAST:event_cmb_conceptoActionPerformed

    private void txta_descripcionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txta_descripcionKeyTyped
        modif_descripcion = true;
        if(!btn_guardar.isEnabled())
            btn_guardar.setEnabled(true);
    }//GEN-LAST:event_txta_descripcionKeyTyped

    /**
    * @param args the command line arguments
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_guardar;
    private javax.swing.JComboBox cmb_concepto;
    private javax.swing.JComboBox cmb_individuo;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private com.toedter.calendar.JDateChooser jcal_fecha_gasto;
    private javax.swing.JTable tabla_gastos_modificaciones;
    private javax.swing.JTextField txt_busqueda;
    private javax.swing.JTextField txt_monto;
    private javax.swing.JTextArea txta_descripcion;
    // End of variables declaration//GEN-END:variables

}
